<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="/session/css/common.css"/>
    <script type="text/javascript" src="/plan/js/jquery.1.9.1.js" ></script>
     <script type="text/javascript" src="/plan/js/layer.js" ></script>
	<script type="text/javascript" src="/person/js/mobileSelect.js"></script>
	<link rel="stylesheet" type="text/css" href="/person/css/mobileSelect.css"/>
	<script type="text/javascript" src="/session/js/rolldate.min.js" ></script>
	<script type="text/javascript" src="/plan/js/rem.js" ></script>
	 <script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
    <title>场次信息</title>
</head>
<body>
	<ul class="order_money" style="padding: 0 0.3rem;background: #fff;margin-bottom: 1.5rem;">
		<!--  <li>
	    		<span class="fontchang" style="font-size: 0.2rem;">{:__('Name')}</span>
	    		<input type="text"  id="name" value="{$row.name}" />
	    </li> -->
		<li style="position: relative;height: 1.1rem;">
	    		<span class="time" style="font-size: 0.2rem;">{:__('Season.Season_time')}</span>
	    		<span class="jt"></span>
	    		<input readonly class="form-control" value="{$row.season_time}"type="text" id="date-group1-4">
	    </li>
	    <li>
			<span class="type" style="font-size: 0.2rem;">{:__('Season.Subject_id')}</span><span class="jt"></span>
			<div id="trigger1" class="trigger1" style="display: inline-block;width: 96%;margin-top: 0.1rem;">
			 	{$row.subject_text}
			</div>
			<input type="hidden" name="" id="type" value="{$row.subject_id}" />								
		</li>
		<li>
			<span class="addr" style="font-size: 0.2rem;">会议{:__('Address')}</span><span class="jt"></span>
			<div id="trigger2" class="trigger2" style="display: inline-block;width: 96%;margin-top: 0.1rem;">
			 	{$row.province_text} {$row.city_text} {$row.area_text} 
			</div>
			 <input type="hidden" name="" id="province" value="{$row.province}" />								
			 <input type="hidden" name="" id="city" value="{$row.city}" />								
			 <input type="hidden" name="" id="area" value="{$row.area}" />								
		</li>
	    <li>
	    		<span class="fontchang" style="font-size: 0.2rem;">详细{:__('Address')}</span>
	    		<input type="text" name="" id="address" value="{$row.address}" />
	    </li>
	    <li>
	    		<span class="fontchang" style="font-size: 0.2rem;">{:__('Season.Gift_books')}</span>
	    		<input type="number" pattern="[0-9]*" name="" id="znum" value="{$row.gift_books}" />
	    </li>
	    {if $row.lecturer_id}
	    <li>
	    		<span class="fontchang" style="font-size: 0.2rem;">{:__('Season.Lecturer_id')}</span>
	    		<div class="choose">
				<div id="divclass">
					<img src="{$row.lecturer_avatar_text}" id="avatar"/>
					<img class="close" src="/session/img/close.png" />
					<p id="username">{$row.lecturer_text}</p>
					<input type="hidden"  value="{$row.lecturer_id}"  id="nameuserid"  />
				</div>
				<div>
					<img  id="updateuserid" style="display: none;" src="/session/img/addwl.png" />
				</div>
			</div>
	    </li>
	    {else}
	     <li>
	    		<span class="fontchang" style="font-size: 0.2rem;">{:__('Season.Lecturer_id')}</span>
	    		<div class="choose" >
				<div id="divclass" style="display: none;">
					<img src="" id="avatar"/>
					<img class="close" src="/session/img/close.png" />
					<p id="username">讲师</p>
					<input type="hidden" value=""  id="nameuserid"  />
				</div>
				<div>
					<img   id="updateuserid" src="/session/img/addwl.png" />
				</div>
			</div>
	    </li>
	    {/if}
	    <li>
	    		<span class="fontchang" style="font-size: 0.2rem;">{:__('Desc')}</span>
	    		<textarea id="beizhu" value="">{$row.desc}</textarea>
	    </li>
	</ul>
	<div class="preserve">保存</div>
</body>
<script>
 wx.config({$json});
 wx.checkJsApi({
    jsApiList: ['selectEnterpriseContact','openEnterpriseChat'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
    success: function(res) {
        // 以键值对的形式返回，可用的api值true，不可用为false
        // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
    }
});
wx.ready(function(){
	var nameuserid = '{$row.lecturer_id}';
  $(document).on('click', "#updateuserid", function () {
     var id = $(this).attr("attrid");
       wx.invoke("selectEnterpriseContact", {
                "fromDepartmentId": 58,// 必填，-1表示打开的通讯录从自己所在部门开始展示, 0表示从最上层开始
                "mode": "single",// 必填，选择模式，single表示单选，multi表示多选
                "type": ["user"],// 必填，选择限制类型，指定department、user中的一个或者多个
                "selectedDepartmentIds": [],// 非必填，已选部门ID列表。用于多次选人时可重入
                "selectedUserIds": [nameuserid]// 非必填，已选用户ID列表。用于多次选人时可重入
            },function(res){
                if (res.err_msg == "selectEnterpriseContact:ok")
                {
                    if(typeof res.result == 'string')
                    {
                        alert('不兼容');
                        res.result = JSON.parse(res.result) //由于目前各个终端尚未完全兼容，需要开发者额外判断result类型以保证在各个终端的兼容性
                    }
                    var selectedDepartmentList = res.result.departmentList;// 已选的部门列表
                    for (var i = 0; i < selectedDepartmentList.length; i++)
                    {
                        var department = selectedDepartmentList[i];
                        var departmentId = department.id;// 已选的单个部门ID
                        var departemntName = department.name;// 已选的单个部门名称
                    }
                    var selectedUserList = res.result.userList; // 已选的成员列表
                    for (var i = 0; i < selectedUserList.length; i++)
                    {
                        var user = selectedUserList[i];
                        var userId = user.id; // 已选的单个成员ID
                        var userName = user.name;// 已选的单个成员名称
                        var userAvatar= user.avatar;// 已选的单个成员头像
                    }
                  $("#avatar").attr("src", userAvatar);
                  $("#nameuserid").val(userId);
                  nameuserid = userId;
                  $("#username").text(userName);
                  $("#updateuserid").hide();
                  $("#divclass").show();
                }
            }
        );
  });
});
</script>
<script>
$(function(){
	$('.close').click(function(){
		$(this).parent().hide();
		$(this).parent().siblings().css('margin-left','0');
		$(this).parent().siblings().children().show();
	});
	//提交表单
	$('.preserve').click(function(){
		var datetime = $('#date-group1-4').val();
		var type = $('#type').val();
		var province = $('#province').val();
		var city = $('#city').val();
		var area = $('#area').val();
		var address = $('#address').val();
		var znum = $('#znum').val();
		var lecturer = $('#nameuserid').val();
		var beizhu = $('#beizhu').val();
	
		if(datetime == ''||datetime == null){
				layer.open({
				content:'请选择开会时间' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}
		if(type == ''||type == null){
				layer.open({
				content:'请选择学校类别' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}
		if(province == ''||province == null){
				layer.open({
				content:'请选择开会地点' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}
		if(address == ''||address == null){
			layer.open({
				content:'请填写详细地址' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}
		if(znum == ''||znum == null){
			layer.open({
				content:'请填写赠书数量' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}
		if(lecturer == ''||lecturer == null){
				layer.open({
				content:'请选择讲师' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}
		var index = layer.open({type: 2});
		$.ajax({
		  type: 'post',
		  url:"" ,
		  data:{name:name,season_time:datetime,subject_id:type,province:province,city:city,area:area,address:address,gift_books:znum,lecturer_id:lecturer,desc:beizhu},
		  dataType: "json",
		  success: function(data){
		    console.log(data);
		  		layer.open({
						content:data.msg,
						skin: 'msg',
						time: 2 //2秒后自动关闭
				});
				layer.close(index);
			  	if(data.code){
			  		 setTimeout(function () {
						window.location.href = "/index/plan/public_view/type/Season/ids/"+data.data;
					},2000);
			  	}
		  }
		});
	 });
	 //字体变化
	$('input').keyup(function(){
		if($(this).val() != ''){
			$(this).siblings('.must').hide();
			$(this).siblings('.fontchang').css('font-size','0.2rem');
		}else{
			$(this).siblings('.must').show();
			$(this).siblings('.fontchang').css('font-size','0.32rem');
		}
	});
	if($('#userid').val() != ''){
		$('#userid').parents('.choose').siblings('.fontchang').css('font-size','0.2rem');
	}else{
		$('#userid').parents('.choose').siblings('.fontchang').css('font-size','0.32rem');
	}
	$('textarea').keyup(function(){
		if($(this).val() != ''){
			$(this).siblings('.must').hide();
			$(this).siblings('.fontchang').css('font-size','0.2rem');
		}else{
			$(this).siblings('.must').show();
			$(this).siblings('.fontchang').css('font-size','0.32rem');
		}
	});
	//日期
	new Rolldate({
		el: '#date-group1-4',
		format: 'YYYY-MM-DD hh:mm',
		beginYear: 2000,
		endYear: 2100,
		confirm: function(date) {
			$('.bitian').hide();
			$('.time').css('font-size','0.2rem');
		},
		cancel: function() {
			console.log('取消');
		}
	})
	var arr = [{$arr}];
	var dearr = [{$dearr}];
	//选择
	var mobileSelect1 = new MobileSelect({
	    trigger: '#trigger1',
	    title: '会议类型',
	    wheels: [{data:arr}],
	    position:[dearr],
		 callback:function(indexArr, data){
		    $('#type').val(data[0].id);
		    $('.type').css('font-size','0.2rem');
		 }  
	});
  var arrarea = [];
  var province = {$row.province};
  var city = {$row.city};
  var area = {$row.area};  
  var province_more = '';
  var city_more = '';
  var area_more = '';
	 $.ajax({
	    type: "post",
	    url: "https://oa.fc62.com/api/ajax/area",
	    dataType: "json",
	       async: false,
	    success: function(res){
	       arrarea = res.data;
	       console.log(arrarea);
	    }
	});
	for (var i = 0; i < arrarea.length; i++) { 
		if(province == arrarea[i]['id']){
			province_more = i;
	    	for (var s = 0; s < arrarea[i]['childs'].length; s++) {
	    		if(city == arrarea[i]['childs'][s]['id']){
	    			city_more = s;
	    			for (var a = 0; a < arrarea[i]['childs'][s]['childs'].length; a++) {
				    		if(area == arrarea[i]['childs'][s]['childs'][a]['id']){

				    			area_more = a;
				    		}
				    	}
	    		}
	    	}
		}
	 }
	 console.log(province_more);
	 console.log(city_more);
	var mobileSelect2 = new MobileSelect({
	    trigger: '#trigger2',
	    title: '地区选择',
	    wheels: [{data:arrarea}],
	    position:[province_more,city_more,area_more],
		 callback:function(indexArr, data){
		    $('#province').val(data[0].id);
		    $('#city').val(data[1].id);
		    $('#area').val(data[2].id);
		    $('.addr').css('font-size','0.2rem');
		 }  
	});
	
});
</script>
</html>
